<?php
    if($_GET['ClienteID'] != null || $_GET['ClienteID'] != ""){
        if($_GET['email'] != "" && $_GET['email'] != null){
            include_once '../../SQL/connector.php';
        $con = new connector();
        $query ="INSERT INTO `Aruana`.`Email`
                    (`email`)
                VALUES
                    ('".$_GET['email']."');";
        $result = $con->executaSql($query);
        if($result){
            $query =    "INSERT INTO Aruana.Pessoa_has_Email
                                (`Pessoa_has_Email`.`Pessoa_idPessoa`,
                                `Pessoa_has_Email`.`Email_idEmail`)
                        VALUES(
                        '".$_GET['ClienteID']."',
                        (SELECT `Email`.`idEmail`
                                FROM Aruana.Email
                                WHERE `Email`.`email` = '".$_GET['email']."'
                                ORDER BY `Email`.`idEmail` DESC
                                LIMIT 1)
                        );";
            $result = $con->executaSql($query);
            if($result){
                echo "Email ".$_GET['email']." adicionado";
            }
            else{
                echo "Erro";
                echo $query;
            }
        }
        else{
            echo "Erro";
            echo $query;
        }

        }
        else{
            echo 'Informação do email inválida!';
        }
    }else{
        echo 'ID do cliente inválido!';
    }

?>

